﻿using eSSP_example.Classes;
using eSSP_example.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.UI.WebControls;
using System.Windows.Forms;

namespace eSSP_example.Cpi
{
    public class ClsGlobalData
    {
        private static ClsGlobalData instance = null;

        private CCpi        cpiHopper;
        private CPayout     spo;

        private List<ApiPaymentDevice> apiPaymentDevices;

        //  access to the CCpi
        public CCpi CpiHopper
        {
            set { cpiHopper = value; }
        }

        //  access to the CPayout
        public CPayout sPayout
        {
            set { spo = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        private ClsGlobalData() {

            apiPaymentDevices = new List<ApiPaymentDevice>();
        }

        /// <summary>
        ///     getInstance
        /// </summary>
        /// <returns></returns>
        public static ClsGlobalData getInstance()
        {
            if  (instance == null)
            {
                instance = new ClsGlobalData();
            }

            return  instance;
        }

        /// <summary>
        ///     buildPaymentDeviceList
        /// </summary>
        /// <returns></returns>
        public List<ApiPaymentDevice> buildPaymentDeviceList()
        {
            List<ApiPaymentDevice> list = new List<ApiPaymentDevice>();

            list.Add(cpiHopper.buildApiPaymentDeviceForCpiHopper());
            list.Add(spo.buildApiPaymentDeviceForSpo());

            return  list;
        }

        /// <summary>
        ///     buildCashStatus
        /// </summary>  
        /// <returns></returns>
        public CashStatus buildCashStatus()
        {
            CashStatus status = new CashStatus();

            CoinStatus  coinStatus = cpiHopper.getCoinStatus();
            BillStatus  billStatus = spo.getBillStatus();

            status.coinsStored = coinStatus.coinsStored;
            status.coinsCashbox = coinStatus.coinsCashbox;

            status.billsStored  = billStatus.billsStored;
            status.billsCashbox = billStatus.billsCashbox;
            
            status.collectableCoinValue = coinStatus.collectableCoinValue;
            status.collectableBillValue = billStatus.collectableBillValue;
            
            status.totalSystemCash = coinStatus.collectableCoinValue + billStatus.collectableBillValue;
            status.totalCollectableCash = coinStatus.collectableCoinValue + billStatus.collectableBillValue;

            return  status;
        }
    }
}
